<div class="layuimini-main">

    <div class="layui-form layuimini-form" lay-filter="editForm">

        <div class="layui-form-item">
            <label class="layui-form-label required">标题</label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="">
                <input type="text" name="title" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入公告标题" value=""
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-block">
                <textarea name="contend" class="layui-textarea" placeholder="请输入公告内容"></textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">有效期</label>
            <div class="layui-input-block">
                <input type="number" name="validity" placeholder="请输入公告时长" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'axios'], function () {
        var form = layui.form,
            layer = layui.layer,
            axios = layui.axios,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            let obj = data.field;

            //异步提交修改
            axios({
                method: "post",
                url: "notice/update",
                data: obj
            }).then(response => {
                if (response.code == 0){
                    layer.msg(response.msg, function (){
                        layui.table.reload("currentTableId");
                        layer.close(parentIndex);
                    })
                }else{
                    layer.msg(response.msg);
                }

            }).catch(error => {
                console.log(error);
            })
            return false;
        });

    });
</script>